home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / javasprites / src / cdf / multipleimagepainter.java < prev   
Encoding:
Java Source  |  2000-09-28  |  1.9 KB  |  68 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. package cdf;
  9.  
  10. import java.awt.*;
  11. import quicktime.app.image.*;
  12.  
  13. class MultipleImagePainter implements Paintable {
  14.     MultipleImagePainter (Image[] ims) {
  15.         images = ims;
  16.     }
  17.     
  18.     int width, height;
  19.     Image[] images;
  20.     int loopslot;
  21.     Rectangle[] r = new Rectangle[1];
  22.     /**
  23.      * Returns the number of images
  24.      */
  25.     public int getNumberOfFrames () { return images.length; }
  26.     
  27.     public void setCurrentFrame (int frame) {
  28.         loopslot = frame;
  29.         if (loopslot < 0) loopslot = 0;
  30.         if (loopslot >= getNumberOfFrames()) loopslot = getNumberOfFrames() - 1;
  31.     }
  32.     
  33.     /** 
  34.      * Sets the current frame - zero based
  35.      */
  36.     public Image getCurrentFrame () {
  37.         return images[loopslot];
  38.     }
  39.  
  40.     /**
  41.      * The Parent object of the Paintable tell the paintable object the size of its available
  42.      * drawing surface. Any drawing done outside of these bounds (originating at 0,0) will
  43.      * be clipped.
  44.      */
  45.     public void newSizeNotified (QTImageDrawer drawer, Dimension d) {
  46.         width = d.width;
  47.         height = d.height;
  48.         r[0] = new Rectangle (width, height);
  49.     }
  50.     
  51.     /**
  52.      * Paint on the graphics. The supplied component is the component from which
  53.      * the graphics object was derived or related to and is also the component
  54.      * that is the object that paint was called upon that has called this method.
  55.      * The Graphics object is what you should paint on.
  56.      * This maybe an on or off screen graphics.
  57.      * You should not cache this graphics object as it can be different
  58.      * between different calls.
  59.      * @param comp the component from which the Graphics object was derived or 
  60.      * related too.
  61.      * @param g the graphics to paint on.
  62.      */
  63.     public Rectangle[] paint (Graphics g) {
  64.         g.drawImage (getCurrentFrame(), 0, 0, null);
  65.         return r;
  66.     }
  67. }
  68.